package com.ow.dva.module.account.service.impl;

import com.ow.dva.config.annotation.DvaCache5M;
import com.ow.dva.module.account.entity.Account;
import com.ow.dva.module.account.entity.AccountInfo;
import com.ow.dva.module.account.entity.AccountPark;
import com.ow.dva.module.account.mapper.AccountMapper;
import com.ow.dva.module.account.mapper.AccountParkMapper;
import com.ow.dva.module.account.service.AccountService;
import com.ow.dva.module.base.service.impl.DvaServiceImpl;
import com.ow.dva.module.park.entity.Park;
import com.ow.dva.module.park.mapper.ParkMapper;
import org.springframework.stereotype.Service;
import com.ow.dva.module.base.entity.param.DvaPage;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 高祥
 * @since 2020-01-09
 * @version V1.0
 */
@Service
public class AccountServiceImpl extends DvaServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public DvaPage<Account> page(DvaPage<Account> page, Map<String, Object> param) {

        return baseMapper.page(page,param);
    }

    @Override
    public Account findByUserName(String userName) {
        
        return baseMapper.findByUserName(userName);
    }

    @Override
    public boolean bindParkBatch(AccountInfo accountInfo, List<String> ids) {
        //删除此管理员绑定的所有停车场
        int i = accountParkMapper.deleteByAccountId(accountInfo.getAccountId());
        System.out.println("删除绑定停车场的条数" + i);
        //重新绑定选中的停车场
        for (String id:ids) {
            Park park = parkMapper.selectById(id);
            if(park != null){
                AccountPark accountPark = new AccountPark(accountInfo.getAccountId(),park.getId(),park.getName(),accountInfo.getName(),accountInfo.getCounty(),accountInfo.getCity());
                accountParkMapper.insert(accountPark);
            }
        }
        return true;
    }

    @Resource
    AccountParkMapper accountParkMapper;
    @Resource
    ParkMapper parkMapper;
}
